package com.example.administrator.szb.activity.webviews;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.text.TextUtils;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.example.administrator.szb.R;
import com.example.administrator.szb.activity.base.BasePresenter;
import com.example.administrator.szb.activity.base.MVPBaseActivity;
import com.example.administrator.szb.util.QTLog;

public class WebViews2Activity  extends MVPBaseActivity {
    private TextView bar_title;
    WebView webview_webview;
    private String url;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_views2);

    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected void setScreen() {

    }

    @Override
    protected void initView() {

        bar_title = findViewById(R.id.bar_title);
        webview_webview = findViewById(R.id.webview_webview);
    }
    private boolean isShowFujian = false;
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void initEvent() {

        url = getIntent().getStringExtra("url");
        if (TextUtils.isEmpty(url)){
            url = "http://www.baidu.com";
        }
        WebSettings webSettings = webview_webview.getSettings();
//支持缩放，默认为true。
        webSettings .setSupportZoom(true);
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
//让缩放显示的最小值为起始
        webview_webview.setInitialScale(5);
//调整图片至适合webview的大小
        webSettings .setUseWideViewPort(true);
// 缩放至屏幕的大小
        webSettings .setLoadWithOverviewMode(true);
//设置默认编码
        webSettings .setDefaultTextEncodingName("utf-8");
////设置自动加载图片
        webSettings .setLoadsImagesAutomatically(true);


        webview_webview.loadUrl(url);
        webview_webview.setWebChromeClient(new WebChromeClient());

//如果访问的页面中要与Javascript交互，则webview必须设置支持Javascript
        webview_webview.getSettings().setJavaScriptEnabled(true);
//设置自适应屏幕，两者合用
        webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT){
            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        webSettings.setBlockNetworkImage(false);


    }


    @Override
    protected void initData() {
        bar_title.setText(getIntent().getStringExtra("bar_title"));
        QTLog.e(getIntent().getStringExtra("bar_title"));
        QTLog.e(getIntent().getStringExtra("url"));
    }
}
